am 6c97742: Always add the bt profile to profile list on the arrive of a

Merge commit '6c97742c88303c65e68fe08257a7ccf841f03866'

* commit '6c97742c88303c65e68fe08257a7ccf841f03866':
  Always add the bt profile to profile list on the arrive of a connect event
This commit is contained in:
Michael Chan
2009-05-06 18:25:41 -07:00
committed by The Android Open Source Project
4 changed files with 59 additions and 42 deletions

View File

@@ -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);

View File

@@ -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());
}
// 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;
int newState = LocalBluetoothProfileManager.getProfileManager(mLocalManager,
profile).convertState(newProfileState);
if (newState == SettingsBtStatus.CONNECTION_STATUS_CONNECTED) {
if (!mProfiles.contains(profile)) {
mProfiles.add(profile);
}
} else {
// Remove the first item and process the next one
workQueue.poll();
}
processCommands();
/* 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();
}
processCommands();
}
}
/*

View File

@@ -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();
}

View File

@@ -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;