am 1ae86869: Merge "Auto connection/disconnection related changes" into jb-mr1-dev
* commit '1ae86869bcc2262b6828102c8a3ee08e68580fa7': Auto connection/disconnection related changes
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
69
core/java/android/bluetooth/BluetoothPbap.java
Normal file → Executable file
69
core/java/android/bluetooth/BluetoothPbap.java
Normal file → Executable file
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user