diff options
author | Michael Chan <mchan@android.com> | 2009-05-06 18:08:58 -0700 |
---|---|---|
committer | Michael Chan <mchan@android.com> | 2009-05-06 18:08:58 -0700 |
commit | 6c97742c88303c65e68fe08257a7ccf841f03866 (patch) | |
tree | 150da99eecc3189bcfb947a38baa75538393c4b4 /src/com/android/settings/bluetooth | |
parent | e94a4e27474a410f6c9d1b2aa4ef8a8b58a8d218 (diff) | |
download | packages_apps_settings-6c97742c88303c65e68fe08257a7ccf841f03866.zip packages_apps_settings-6c97742c88303c65e68fe08257a7ccf841f03866.tar.gz packages_apps_settings-6c97742c88303c65e68fe08257a7ccf841f03866.tar.bz2 |
Always add the bt profile to profile list on the arrive of a connect event
Always add the bt profile to profile list on the arrive of a connect event. Previously,
the connect event is ignored if it is a profile that's not known ahead of time.
Diffstat (limited to 'src/com/android/settings/bluetooth')
4 files changed, 58 insertions, 41 deletions
diff --git a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java index 71b91d3..af64c98 100644 --- a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java +++ b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java @@ -18,8 +18,8 @@ package com.android.settings.bluetooth; import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothDevice; -import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothError; +import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothIntent; import android.content.BroadcastReceiver; import android.content.Context; @@ -27,6 +27,8 @@ import android.content.Intent; import android.content.IntentFilter; import android.util.Log; +import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile; + /** * BluetoothEventRedirector receives broadcasts and callbacks from the Bluetooth * API and dispatches the event on the UI thread to the right class in the @@ -89,9 +91,8 @@ public class BluetoothEventRedirector { Log.i(TAG, "Failed to connect BT headset"); } - boolean transientState = !(newState == BluetoothHeadset.STATE_CONNECTED - || newState == BluetoothHeadset.STATE_DISCONNECTED); - mManager.getLocalDeviceManager().onProfileStateChanged(address,transientState); + mManager.getLocalDeviceManager().onProfileStateChanged(address, + Profile.HEADSET, newState); } else if (action.equals(BluetoothA2dp.SINK_STATE_CHANGED_ACTION)) { int newState = intent.getIntExtra(BluetoothA2dp.SINK_STATE, 0); @@ -101,9 +102,8 @@ public class BluetoothEventRedirector { Log.i(TAG, "Failed to connect BT A2DP"); } - boolean transientState = !(newState == BluetoothA2dp.STATE_CONNECTED - || newState == BluetoothA2dp.STATE_DISCONNECTED); - mManager.getLocalDeviceManager().onProfileStateChanged(address, transientState); + mManager.getLocalDeviceManager().onProfileStateChanged(address, + Profile.A2DP, newState); } else if (action.equals(BluetoothIntent.REMOTE_DEVICE_CLASS_UPDATED_ACTION)) { mManager.getLocalDeviceManager().onBtClassChanged(address); diff --git a/src/com/android/settings/bluetooth/LocalBluetoothDevice.java b/src/com/android/settings/bluetooth/LocalBluetoothDevice.java index 5c79761..5259d7b 100644 --- a/src/com/android/settings/bluetooth/LocalBluetoothDevice.java +++ b/src/com/android/settings/bluetooth/LocalBluetoothDevice.java @@ -16,9 +16,6 @@ package com.android.settings.bluetooth; -import com.android.settings.R; -import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile; - import android.app.AlertDialog; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; @@ -32,6 +29,9 @@ import android.view.ContextMenu; import android.view.Menu; import android.view.MenuItem; +import com.android.settings.R; +import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile; + import java.text.DateFormat; import java.util.ArrayList; import java.util.Date; @@ -210,32 +210,46 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> { return successful; } - public void onProfileStateChanged() { + public void onProfileStateChanged(Profile profile, int newProfileState) { if (D) { Log.d(TAG, "onProfileStateChanged:" + workQueue.toString()); } - BluetoothJob job = workQueue.peek(); - if (job == null) { - return; - } else if (job.device.mAddress != mAddress) { - // This can happen in 2 cases: 1) BT device initiated pairing and - // 2) disconnects of one headset that's triggered by connects of - // another. - if (D) { - Log.d(TAG, "mAddresses:" + mAddress + " != head:" + job.toString()); + + int newState = LocalBluetoothProfileManager.getProfileManager(mLocalManager, + profile).convertState(newProfileState); + + if (newState == SettingsBtStatus.CONNECTION_STATUS_CONNECTED) { + if (!mProfiles.contains(profile)) { + mProfiles.add(profile); } + } - // Check to see if we need to remove the stale items from the queue - if (!pruneQueue(null)) { - // nothing in the queue was modify. Just ignore the notification and return. + /* Ignore the transient states e.g. connecting, disconnecting */ + if (newState == SettingsBtStatus.CONNECTION_STATUS_CONNECTED || + newState == SettingsBtStatus.CONNECTION_STATUS_DISCONNECTED) { + BluetoothJob job = workQueue.peek(); + if (job == null) { return; + } else if (job.device.mAddress != mAddress) { + // This can happen in 2 cases: 1) BT device initiated pairing and + // 2) disconnects of one headset that's triggered by connects of + // another. + if (D) { + Log.d(TAG, "mAddresses:" + mAddress + " != head:" + job.toString()); + } + + // Check to see if we need to remove the stale items from the queue + if (!pruneQueue(null)) { + // nothing in the queue was modify. Just ignore the notification and return. + return; + } + } else { + // Remove the first item and process the next one + workQueue.poll(); } - } else { - // Remove the first item and process the next one - workQueue.poll(); - } - processCommands(); + processCommands(); + } } /* diff --git a/src/com/android/settings/bluetooth/LocalBluetoothDeviceManager.java b/src/com/android/settings/bluetooth/LocalBluetoothDeviceManager.java index 9e46b4d..2c70fd2 100644 --- a/src/com/android/settings/bluetooth/LocalBluetoothDeviceManager.java +++ b/src/com/android/settings/bluetooth/LocalBluetoothDeviceManager.java @@ -21,6 +21,7 @@ import android.util.Log; import com.android.settings.R; import com.android.settings.bluetooth.LocalBluetoothManager.Callback; +import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile; import java.util.ArrayList; import java.util.List; @@ -199,13 +200,12 @@ public class LocalBluetoothDeviceManager { mLocalManager.showError(address, R.string.bluetooth_error_title, errorMsg); } - public synchronized void onProfileStateChanged(String address, boolean transientState) { + public synchronized void onProfileStateChanged(String address, Profile profile, + int newProfileState) { LocalBluetoothDevice device = findDevice(address); if (device == null) return; - - if (!transientState) { - device.onProfileStateChanged(); - } + + device.onProfileStateChanged(profile, newProfileState); device.refresh(); } diff --git a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java index 24563a7..b396732 100644 --- a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java +++ b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java @@ -16,17 +16,14 @@ package com.android.settings.bluetooth; -import com.android.settings.R; - import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothError; import android.bluetooth.BluetoothHeadset; -import android.bluetooth.BluetoothClass; -import android.content.Context; -import android.content.SharedPreferences; import android.os.Handler; import android.text.TextUtils; +import com.android.settings.R; + import java.util.HashMap; import java.util.List; import java.util.Map; @@ -102,6 +99,8 @@ public abstract class LocalBluetoothProfileManager { public abstract int getSummary(String address); + public abstract int convertState(int a2dpState); + public abstract boolean isPreferred(String address); public abstract void setPreferred(String address, boolean preferred); @@ -176,7 +175,8 @@ public abstract class LocalBluetoothProfileManager { preferred ? BluetoothA2dp.PRIORITY_AUTO : BluetoothA2dp.PRIORITY_OFF); } - private static int convertState(int a2dpState) { + @Override + public int convertState(int a2dpState) { switch (a2dpState) { case BluetoothA2dp.STATE_CONNECTED: return SettingsBtStatus.CONNECTION_STATUS_CONNECTED; @@ -217,7 +217,9 @@ public abstract class LocalBluetoothProfileManager { */ String address = mService.getHeadsetAddress(); if (TextUtils.isEmpty(address)) return; - mLocalManager.getLocalDeviceManager().onProfileStateChanged(address, true); + mLocalManager.getLocalDeviceManager() + .onProfileStateChanged(address, Profile.HEADSET, + BluetoothHeadset.STATE_CONNECTED); } }); } @@ -273,7 +275,8 @@ public abstract class LocalBluetoothProfileManager { preferred ? BluetoothHeadset.PRIORITY_AUTO : BluetoothHeadset.PRIORITY_OFF); } - private static int convertState(int headsetState) { + @Override + public int convertState(int headsetState) { switch (headsetState) { case BluetoothHeadset.STATE_CONNECTED: return SettingsBtStatus.CONNECTION_STATUS_CONNECTED; |