diff --git a/core/java/android/bluetooth/BluetoothA2dp.java b/core/java/android/bluetooth/BluetoothA2dp.java index 1b415e5eb9b65..6e2278d460aba 100755 --- a/core/java/android/bluetooth/BluetoothA2dp.java +++ b/core/java/android/bluetooth/BluetoothA2dp.java @@ -337,9 +337,7 @@ public final class BluetoothA2dp implements BluetoothProfile { if (mService != null && isEnabled() && isValidDevice(device)) { if (priority != BluetoothProfile.PRIORITY_OFF && - priority != BluetoothProfile.PRIORITY_ON && - priority != BluetoothProfile.PRIORITY_UNDEFINED && - priority != BluetoothProfile.PRIORITY_AUTO_CONNECT) { + priority != BluetoothProfile.PRIORITY_ON){ return false; } try { diff --git a/core/java/android/bluetooth/BluetoothHeadset.java b/core/java/android/bluetooth/BluetoothHeadset.java index 8e6ebafda50f7..541b69fad2b45 100755 --- a/core/java/android/bluetooth/BluetoothHeadset.java +++ b/core/java/android/bluetooth/BluetoothHeadset.java @@ -455,9 +455,7 @@ public final class BluetoothHeadset implements BluetoothProfile { if (mService != null && isEnabled() && isValidDevice(device)) { if (priority != BluetoothProfile.PRIORITY_OFF && - priority != BluetoothProfile.PRIORITY_ON && - priority != BluetoothProfile.PRIORITY_UNDEFINED && - priority != BluetoothProfile.PRIORITY_AUTO_CONNECT) { + priority != BluetoothProfile.PRIORITY_ON) { return false; } try { diff --git a/core/java/android/bluetooth/BluetoothPbap.java b/core/java/android/bluetooth/BluetoothPbap.java old mode 100644 new mode 100755 index 639ae1a96d59c..7de2ef61a0748 --- a/core/java/android/bluetooth/BluetoothPbap.java +++ b/core/java/android/bluetooth/BluetoothPbap.java @@ -70,6 +70,7 @@ public class BluetoothPbap { private IBluetoothPbap mService; private final Context mContext; private ServiceListener mServiceListener; + private BluetoothAdapter mAdapter; /** There was an error trying to obtain the state */ public static final int STATE_ERROR = -1; @@ -96,7 +97,7 @@ public class BluetoothPbap { * this callback before making IPC calls on the BluetoothPbap * service. */ - public void onServiceConnected(); + public void onServiceConnected(BluetoothPbap proxy); /** * Called to notify the client that this proxy object has been @@ -108,12 +109,54 @@ public class BluetoothPbap { public void onServiceDisconnected(); } + final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback = + new IBluetoothStateChangeCallback.Stub() { + public void onBluetoothStateChange(boolean up) { + if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up); + if (!up) { + if (DBG) Log.d(TAG,"Unbinding service..."); + synchronized (mConnection) { + try { + mService = null; + mContext.unbindService(mConnection); + } catch (Exception re) { + Log.e(TAG,"",re); + } + } + } else { + synchronized (mConnection) { + try { + if (mService == null) { + if (DBG) Log.d(TAG,"Binding service..."); + if (!mContext.bindService( + new Intent(IBluetoothPbap.class.getName()), + mConnection, 0)) { + Log.e(TAG, "Could not bind to Bluetooth PBAP Service"); + } + } + } catch (Exception re) { + Log.e(TAG,"",re); + } + } + } + } + }; + /** * Create a BluetoothPbap proxy object. */ public BluetoothPbap(Context context, ServiceListener l) { mContext = context; mServiceListener = l; + mAdapter = BluetoothAdapter.getDefaultAdapter(); + IBluetoothManager mgr = mAdapter.getBluetoothManager(); + if (mgr != null) { + try { + mgr.registerStateChangeCallback(mBluetoothStateChangeCallback); + } catch (RemoteException e) { + Log.e(TAG,"",e); + } + } if (!context.bindService(new Intent(IBluetoothPbap.class.getName()), mConnection, 0)) { Log.e(TAG, "Could not bind to Bluetooth Pbap Service"); } @@ -134,9 +177,25 @@ public class BluetoothPbap { * are ok. */ public synchronized void close() { - if (mConnection != null) { - mContext.unbindService(mConnection); - mConnection = null; + IBluetoothManager mgr = mAdapter.getBluetoothManager(); + if (mgr != null) { + try { + mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback); + } catch (Exception e) { + Log.e(TAG,"",e); + } + } + + synchronized (mConnection) { + if (mService != null) { + try { + mService = null; + mContext.unbindService(mConnection); + mConnection = null; + } catch (Exception re) { + Log.e(TAG,"",re); + } + } } mServiceListener = null; } @@ -240,7 +299,7 @@ public class BluetoothPbap { if (DBG) log("Proxy object connected"); mService = IBluetoothPbap.Stub.asInterface(service); if (mServiceListener != null) { - mServiceListener.onServiceConnected(); + mServiceListener.onServiceConnected(BluetoothPbap.this); } } public void onServiceDisconnected(ComponentName className) { diff --git a/core/java/android/bluetooth/BluetoothProfile.java b/core/java/android/bluetooth/BluetoothProfile.java index eada27c7b0d47..1920efa52f876 100755 --- a/core/java/android/bluetooth/BluetoothProfile.java +++ b/core/java/android/bluetooth/BluetoothProfile.java @@ -114,13 +114,6 @@ public interface BluetoothProfile { * */ public static final int PRIORITY_UNDEFINED = -1; - /** - * This Intent is sent to initiate the other profile connections which are enabled - * @hide - **/ - public static final String ACTION_CONNECT_OTHER_PROFILES = - "android.bluetooth.profile.CONNECT_OTHER_PROFILES"; - /** * Get connected devices for this specific profile. *