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.
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;
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
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);
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);
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;
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;
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();
+ }
}
/*
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;
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();
}
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;
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);
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;
*/
String address = mService.getHeadsetAddress();
if (TextUtils.isEmpty(address)) return;
- mLocalManager.getLocalDeviceManager().onProfileStateChanged(address, true);
+ mLocalManager.getLocalDeviceManager()
+ .onProfileStateChanged(address, Profile.HEADSET,
+ BluetoothHeadset.STATE_CONNECTED);
}
});
}
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;