Skip to content

Commit 6f6c545

Browse files
Ganesh Ganapathi BattaMatthew Xie
authored andcommitted
Auto connection/disconnection related changes
Remove ACTION_CONNECT_OTHER_PROFILES as it is no longer used Allow only PRIORITY_ON and PRIORTY_OFF as priority params for SetPriority() API in BluetoothA2DP and BluetoothHeadset BluetoothPBAP: Pass on proxy object as part of Service Connected callback Change-Id: Ida00fc2b7d1dcb91b01f7ddd2cea482367a3b334
1 parent 3c91724 commit 6f6c545

File tree

4 files changed

+66
-18
lines changed

4 files changed

+66
-18
lines changed

core/java/android/bluetooth/BluetoothA2dp.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,7 @@ public boolean setPriority(BluetoothDevice device, int priority) {
337337
if (mService != null && isEnabled()
338338
&& isValidDevice(device)) {
339339
if (priority != BluetoothProfile.PRIORITY_OFF &&
340-
priority != BluetoothProfile.PRIORITY_ON &&
341-
priority != BluetoothProfile.PRIORITY_UNDEFINED &&
342-
priority != BluetoothProfile.PRIORITY_AUTO_CONNECT) {
340+
priority != BluetoothProfile.PRIORITY_ON){
343341
return false;
344342
}
345343
try {

core/java/android/bluetooth/BluetoothHeadset.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,7 @@ public boolean setPriority(BluetoothDevice device, int priority) {
455455
if (mService != null && isEnabled() &&
456456
isValidDevice(device)) {
457457
if (priority != BluetoothProfile.PRIORITY_OFF &&
458-
priority != BluetoothProfile.PRIORITY_ON &&
459-
priority != BluetoothProfile.PRIORITY_UNDEFINED &&
460-
priority != BluetoothProfile.PRIORITY_AUTO_CONNECT) {
458+
priority != BluetoothProfile.PRIORITY_ON) {
461459
return false;
462460
}
463461
try {

core/java/android/bluetooth/BluetoothPbap.java

100644100755
Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public class BluetoothPbap {
7070
private IBluetoothPbap mService;
7171
private final Context mContext;
7272
private ServiceListener mServiceListener;
73+
private BluetoothAdapter mAdapter;
7374

7475
/** There was an error trying to obtain the state */
7576
public static final int STATE_ERROR = -1;
@@ -96,7 +97,7 @@ public interface ServiceListener {
9697
* this callback before making IPC calls on the BluetoothPbap
9798
* service.
9899
*/
99-
public void onServiceConnected();
100+
public void onServiceConnected(BluetoothPbap proxy);
100101

101102
/**
102103
* Called to notify the client that this proxy object has been
@@ -108,12 +109,54 @@ public interface ServiceListener {
108109
public void onServiceDisconnected();
109110
}
110111

112+
final private IBluetoothStateChangeCallback mBluetoothStateChangeCallback =
113+
new IBluetoothStateChangeCallback.Stub() {
114+
public void onBluetoothStateChange(boolean up) {
115+
if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up);
116+
if (!up) {
117+
if (DBG) Log.d(TAG,"Unbinding service...");
118+
synchronized (mConnection) {
119+
try {
120+
mService = null;
121+
mContext.unbindService(mConnection);
122+
} catch (Exception re) {
123+
Log.e(TAG,"",re);
124+
}
125+
}
126+
} else {
127+
synchronized (mConnection) {
128+
try {
129+
if (mService == null) {
130+
if (DBG) Log.d(TAG,"Binding service...");
131+
if (!mContext.bindService(
132+
new Intent(IBluetoothPbap.class.getName()),
133+
mConnection, 0)) {
134+
Log.e(TAG, "Could not bind to Bluetooth PBAP Service");
135+
}
136+
}
137+
} catch (Exception re) {
138+
Log.e(TAG,"",re);
139+
}
140+
}
141+
}
142+
}
143+
};
144+
111145
/**
112146
* Create a BluetoothPbap proxy object.
113147
*/
114148
public BluetoothPbap(Context context, ServiceListener l) {
115149
mContext = context;
116150
mServiceListener = l;
151+
mAdapter = BluetoothAdapter.getDefaultAdapter();
152+
IBluetoothManager mgr = mAdapter.getBluetoothManager();
153+
if (mgr != null) {
154+
try {
155+
mgr.registerStateChangeCallback(mBluetoothStateChangeCallback);
156+
} catch (RemoteException e) {
157+
Log.e(TAG,"",e);
158+
}
159+
}
117160
if (!context.bindService(new Intent(IBluetoothPbap.class.getName()), mConnection, 0)) {
118161
Log.e(TAG, "Could not bind to Bluetooth Pbap Service");
119162
}
@@ -134,9 +177,25 @@ protected void finalize() throws Throwable {
134177
* are ok.
135178
*/
136179
public synchronized void close() {
137-
if (mConnection != null) {
138-
mContext.unbindService(mConnection);
139-
mConnection = null;
180+
IBluetoothManager mgr = mAdapter.getBluetoothManager();
181+
if (mgr != null) {
182+
try {
183+
mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback);
184+
} catch (Exception e) {
185+
Log.e(TAG,"",e);
186+
}
187+
}
188+
189+
synchronized (mConnection) {
190+
if (mService != null) {
191+
try {
192+
mService = null;
193+
mContext.unbindService(mConnection);
194+
mConnection = null;
195+
} catch (Exception re) {
196+
Log.e(TAG,"",re);
197+
}
198+
}
140199
}
141200
mServiceListener = null;
142201
}
@@ -240,7 +299,7 @@ public void onServiceConnected(ComponentName className, IBinder service) {
240299
if (DBG) log("Proxy object connected");
241300
mService = IBluetoothPbap.Stub.asInterface(service);
242301
if (mServiceListener != null) {
243-
mServiceListener.onServiceConnected();
302+
mServiceListener.onServiceConnected(BluetoothPbap.this);
244303
}
245304
}
246305
public void onServiceDisconnected(ComponentName className) {

core/java/android/bluetooth/BluetoothProfile.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,6 @@ public interface BluetoothProfile {
114114
* */
115115
public static final int PRIORITY_UNDEFINED = -1;
116116

117-
/**
118-
* This Intent is sent to initiate the other profile connections which are enabled
119-
* @hide
120-
**/
121-
public static final String ACTION_CONNECT_OTHER_PROFILES =
122-
"android.bluetooth.profile.CONNECT_OTHER_PROFILES";
123-
124117
/**
125118
* Get connected devices for this specific profile.
126119
*

0 commit comments

Comments
 (0)