Loading src/com/android/bluetooth/btservice/AdapterService.java +5 −13 Original line number Diff line number Diff line Loading @@ -1706,10 +1706,12 @@ public class AdapterService extends Service { return; } for (BluetoothDevice device : bondedDevices) { if (pbapClientService.getPriority(device) >= BluetoothProfile.PRIORITY_ON ){ debugLog("autoConnectPbapClient() - Connecting PBAP Client with " + device.toString()); pbapClientService.connect(device); } } } public void connectOtherProfile(BluetoothDevice device, int firstProfileStatus){ Loading Loading @@ -1764,16 +1766,6 @@ public class AdapterService extends Service { } } private void adjustOtherSinkPriorities(A2dpService a2dpService, BluetoothDevice connectedDevice) { for (BluetoothDevice device : getBondedDevices()) { if (a2dpService.getPriority(device) >= BluetoothProfile.PRIORITY_AUTO_CONNECT && !device.equals(connectedDevice)) { a2dpService.setPriority(device, BluetoothProfile.PRIORITY_ON); } } } void setProfileAutoConnectionPriority (BluetoothDevice device, int profileId){ if (profileId == BluetoothProfile.HEADSET) { HeadsetService hsService = HeadsetService.getHeadsetService(); Loading src/com/android/bluetooth/pbapclient/PbapClientService.java +54 −12 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.os.RemoteException; import android.provider.Settings; import android.util.Log; import android.provider.ContactsContract; Loading @@ -42,6 +43,7 @@ import com.android.vcard.VCardEntry; import java.lang.ref.WeakReference; import java.util.Arrays; import java.util.ArrayList; import java.util.List; import java.util.HashMap; Loading Loading @@ -110,7 +112,7 @@ public class PbapClientService extends ProfileService { } catch (Exception e) { Log.w(TAG,"Unable to unregister sap receiver",e); } mClient.handleDisconnect(null); mClient.disconnect(null); return true; } Loading @@ -127,20 +129,16 @@ public class PbapClientService extends ProfileService { String action = intent.getAction(); if (action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if(getPriority(device) >= BluetoothProfile.PRIORITY_ON) { connect(device); } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) { } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); disconnect(device); } } } /** * Handler for incoming service calls */ Loading Loading @@ -213,6 +211,24 @@ public class PbapClientService extends ProfileService { } return service.getConnectionState(device); } public boolean setPriority(BluetoothDevice device, int priority) { PbapClientService service = getService(); if (service == null) { return false; } return service.setPriority(device, priority); } public int getPriority(BluetoothDevice device) { PbapClientService service = getService(); if (service == null) { return BluetoothProfile.PRIORITY_UNDEFINED; } return service.getPriority(device); } } Loading Loading @@ -264,14 +280,17 @@ public class PbapClientService extends ProfileService { connectionState == BluetoothProfile.STATE_CONNECTING) { return false; } mClient.handleConnect(device); if (getPriority(device)>BluetoothProfile.PRIORITY_OFF) { mClient.connect(device); return true; } return false; } boolean disconnect(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission"); mClient.handleDisconnect(device); mClient.disconnect(device); return true; } public List<BluetoothDevice> getConnectedDevices() { Loading @@ -283,6 +302,7 @@ public class PbapClientService extends ProfileService { private List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); int clientState = mClient.getConnectionState(); Log.d(TAG,"getDevicesMatchingConnectionStates " + Arrays.toString(states) + " == " + clientState); List<BluetoothDevice> deviceList = new ArrayList<BluetoothDevice>(); for (int state : states) { if (clientState == state) { Loading @@ -302,4 +322,26 @@ public class PbapClientService extends ProfileService { } return BluetoothProfile.STATE_DISCONNECTED; } public boolean setPriority(BluetoothDevice device, int priority) { enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); Settings.Global.putInt(getContentResolver(), Settings.Global.getBluetoothPbapClientPriorityKey(device.getAddress()), priority); if (DBG) { Log.d(TAG,"Saved priority " + device + " = " + priority); } return true; } public int getPriority(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); int priority = Settings.Global.getInt(getContentResolver(), Settings.Global.getBluetoothPbapClientPriorityKey(device.getAddress()), BluetoothProfile.PRIORITY_UNDEFINED); return priority; } } src/com/android/bluetooth/pbapclient/PbapPCEClient.java +122 −43 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ import android.util.Log; import android.util.Pair; import com.android.vcard.VCardEntry; import com.android.bluetooth.pbapclient.BluetoothPbapClient; import com.android.bluetooth.btservice.ProfileService; import com.android.bluetooth.R; import java.util.ArrayDeque; Loading Loading @@ -67,7 +67,7 @@ public class PbapPCEClient implements PbapHandler.PbapListener { private BluetoothPbapClient mClient; private boolean mClientConnected = false; private PbapHandler mHandler; private Handler mSelfHandler; private ConnectionHandler mConnectionHandler; private PullRequest mLastPull; private HandlerThread mContactHandlerThread; private Handler mContactHandler; Loading @@ -77,7 +77,7 @@ public class PbapPCEClient implements PbapHandler.PbapListener { PbapPCEClient(Context context) { mContext = context; mSelfHandler = new Handler(mContext.getMainLooper()); mConnectionHandler = new ConnectionHandler(mContext.getMainLooper()); mHandler = new PbapHandler(this); mAccountManager = AccountManager.get(mContext); mContactHandlerThread = new HandlerThread("PBAP contact handler", Loading Loading @@ -154,14 +154,73 @@ public class PbapPCEClient implements PbapHandler.PbapListener { mClientConnected = status; if (mClientConnected == false) { // If we are disconnected then whatever the current device is we should simply clean up. handleDisconnect(null); onConnectionStateChanged(mDevice, BluetoothProfile.STATE_CONNECTING, BluetoothProfile.STATE_DISCONNECTED); disconnect(null); } if (mClientConnected == true) { onConnectionStateChanged(mDevice, BluetoothProfile.STATE_CONNECTING, BluetoothProfile.STATE_CONNECTED); processNextRequest(); } } public void handleConnect(BluetoothDevice device) { private class ConnectionHandler extends Handler { public static final int EVENT_CONNECT = 1; public static final int EVENT_DISCONNECT = 2; public ConnectionHandler(Looper looper) { super(looper); } @Override public void handleMessage(Message msg) { if (DBG) { Log.d(TAG, "Connection Handler Message " + msg.what + " with " + msg.obj); } switch (msg.what) { case EVENT_CONNECT: if (msg.obj instanceof BluetoothDevice) { BluetoothDevice device = (BluetoothDevice) msg.obj; int oldState = getConnectionState(); if (oldState != BluetoothProfile.STATE_DISCONNECTED) { return; } onConnectionStateChanged(device, oldState, BluetoothProfile.STATE_CONNECTING); handleConnect(device); } else { Log.e(TAG, "Invalid instance in Connection Handler:Connect"); } break; case EVENT_DISCONNECT: if (mDevice == null) { return; } if (msg.obj == null || msg.obj instanceof BluetoothDevice) { BluetoothDevice device = (BluetoothDevice) msg.obj; if (!mDevice.equals(device)) { return; } int oldState = getConnectionState(); handleDisconnect(device); int newState = getConnectionState(); if (device != null) { onConnectionStateChanged(device, oldState, newState); } } else { Log.e(TAG, "Invalid instance in Connection Handler:Disconnect"); } break; default: Log.e(TAG, "Unknown Request to Connection Handler"); break; } } private void handleConnect(BluetoothDevice device) { if (device == null) { throw new IllegalStateException(TAG + ":Connect with null device!"); } else if (mDevice != null && !mDevice.equals(device)) { Loading @@ -186,7 +245,7 @@ public class PbapPCEClient implements PbapHandler.PbapListener { mClient.connect(); } public void handleDisconnect(BluetoothDevice device) { private void handleDisconnect(BluetoothDevice device) { Log.w(TAG, "pbap disconnecting from = " + device); if (device == null) { Loading @@ -202,6 +261,25 @@ public class PbapPCEClient implements PbapHandler.PbapListener { } resetState(); } } private void onConnectionStateChanged(BluetoothDevice device, int prevState, int state) { Intent intent = new Intent(android.bluetooth.BluetoothPbapClient.ACTION_CONNECTION_STATE_CHANGED); intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState); intent.putExtra(BluetoothProfile.EXTRA_STATE, state); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); mContext.sendBroadcast(intent, ProfileService.BLUETOOTH_PERM); Log.d(TAG,"Connection state " + device + ": " + prevState + "->" + state); } public void connect(BluetoothDevice device) { mConnectionHandler.obtainMessage(ConnectionHandler.EVENT_CONNECT,device).sendToTarget(); } public void disconnect(BluetoothDevice device) { mConnectionHandler.obtainMessage(ConnectionHandler.EVENT_DISCONNECT,device).sendToTarget(); } public void start() { if (mDevice != null) { Loading Loading @@ -293,6 +371,8 @@ public class PbapPCEClient implements PbapHandler.PbapListener { if (msg.obj instanceof Account) { Account account = (Account) msg.obj; addAccount(account); } else { Log.e(TAG, "invalid Instance in Contact Handler: Add Account"); } break; Loading @@ -300,9 +380,8 @@ public class PbapPCEClient implements PbapHandler.PbapListener { if (msg.obj instanceof PullRequest) { PullRequest req = (PullRequest) msg.obj; req.onPullComplete(); } else { Log.w(TAG, "invalid Instance in contact handler"); } else { Log.e(TAG, "invalid Instance in Contact Handler: Add Contacts"); } break; Loading Loading
src/com/android/bluetooth/btservice/AdapterService.java +5 −13 Original line number Diff line number Diff line Loading @@ -1706,10 +1706,12 @@ public class AdapterService extends Service { return; } for (BluetoothDevice device : bondedDevices) { if (pbapClientService.getPriority(device) >= BluetoothProfile.PRIORITY_ON ){ debugLog("autoConnectPbapClient() - Connecting PBAP Client with " + device.toString()); pbapClientService.connect(device); } } } public void connectOtherProfile(BluetoothDevice device, int firstProfileStatus){ Loading Loading @@ -1764,16 +1766,6 @@ public class AdapterService extends Service { } } private void adjustOtherSinkPriorities(A2dpService a2dpService, BluetoothDevice connectedDevice) { for (BluetoothDevice device : getBondedDevices()) { if (a2dpService.getPriority(device) >= BluetoothProfile.PRIORITY_AUTO_CONNECT && !device.equals(connectedDevice)) { a2dpService.setPriority(device, BluetoothProfile.PRIORITY_ON); } } } void setProfileAutoConnectionPriority (BluetoothDevice device, int profileId){ if (profileId == BluetoothProfile.HEADSET) { HeadsetService hsService = HeadsetService.getHeadsetService(); Loading
src/com/android/bluetooth/pbapclient/PbapClientService.java +54 −12 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.os.RemoteException; import android.provider.Settings; import android.util.Log; import android.provider.ContactsContract; Loading @@ -42,6 +43,7 @@ import com.android.vcard.VCardEntry; import java.lang.ref.WeakReference; import java.util.Arrays; import java.util.ArrayList; import java.util.List; import java.util.HashMap; Loading Loading @@ -110,7 +112,7 @@ public class PbapClientService extends ProfileService { } catch (Exception e) { Log.w(TAG,"Unable to unregister sap receiver",e); } mClient.handleDisconnect(null); mClient.disconnect(null); return true; } Loading @@ -127,20 +129,16 @@ public class PbapClientService extends ProfileService { String action = intent.getAction(); if (action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if(getPriority(device) >= BluetoothProfile.PRIORITY_ON) { connect(device); } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) { } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); disconnect(device); } } } /** * Handler for incoming service calls */ Loading Loading @@ -213,6 +211,24 @@ public class PbapClientService extends ProfileService { } return service.getConnectionState(device); } public boolean setPriority(BluetoothDevice device, int priority) { PbapClientService service = getService(); if (service == null) { return false; } return service.setPriority(device, priority); } public int getPriority(BluetoothDevice device) { PbapClientService service = getService(); if (service == null) { return BluetoothProfile.PRIORITY_UNDEFINED; } return service.getPriority(device); } } Loading Loading @@ -264,14 +280,17 @@ public class PbapClientService extends ProfileService { connectionState == BluetoothProfile.STATE_CONNECTING) { return false; } mClient.handleConnect(device); if (getPriority(device)>BluetoothProfile.PRIORITY_OFF) { mClient.connect(device); return true; } return false; } boolean disconnect(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission"); mClient.handleDisconnect(device); mClient.disconnect(device); return true; } public List<BluetoothDevice> getConnectedDevices() { Loading @@ -283,6 +302,7 @@ public class PbapClientService extends ProfileService { private List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); int clientState = mClient.getConnectionState(); Log.d(TAG,"getDevicesMatchingConnectionStates " + Arrays.toString(states) + " == " + clientState); List<BluetoothDevice> deviceList = new ArrayList<BluetoothDevice>(); for (int state : states) { if (clientState == state) { Loading @@ -302,4 +322,26 @@ public class PbapClientService extends ProfileService { } return BluetoothProfile.STATE_DISCONNECTED; } public boolean setPriority(BluetoothDevice device, int priority) { enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); Settings.Global.putInt(getContentResolver(), Settings.Global.getBluetoothPbapClientPriorityKey(device.getAddress()), priority); if (DBG) { Log.d(TAG,"Saved priority " + device + " = " + priority); } return true; } public int getPriority(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); int priority = Settings.Global.getInt(getContentResolver(), Settings.Global.getBluetoothPbapClientPriorityKey(device.getAddress()), BluetoothProfile.PRIORITY_UNDEFINED); return priority; } }
src/com/android/bluetooth/pbapclient/PbapPCEClient.java +122 −43 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ import android.util.Log; import android.util.Pair; import com.android.vcard.VCardEntry; import com.android.bluetooth.pbapclient.BluetoothPbapClient; import com.android.bluetooth.btservice.ProfileService; import com.android.bluetooth.R; import java.util.ArrayDeque; Loading Loading @@ -67,7 +67,7 @@ public class PbapPCEClient implements PbapHandler.PbapListener { private BluetoothPbapClient mClient; private boolean mClientConnected = false; private PbapHandler mHandler; private Handler mSelfHandler; private ConnectionHandler mConnectionHandler; private PullRequest mLastPull; private HandlerThread mContactHandlerThread; private Handler mContactHandler; Loading @@ -77,7 +77,7 @@ public class PbapPCEClient implements PbapHandler.PbapListener { PbapPCEClient(Context context) { mContext = context; mSelfHandler = new Handler(mContext.getMainLooper()); mConnectionHandler = new ConnectionHandler(mContext.getMainLooper()); mHandler = new PbapHandler(this); mAccountManager = AccountManager.get(mContext); mContactHandlerThread = new HandlerThread("PBAP contact handler", Loading Loading @@ -154,14 +154,73 @@ public class PbapPCEClient implements PbapHandler.PbapListener { mClientConnected = status; if (mClientConnected == false) { // If we are disconnected then whatever the current device is we should simply clean up. handleDisconnect(null); onConnectionStateChanged(mDevice, BluetoothProfile.STATE_CONNECTING, BluetoothProfile.STATE_DISCONNECTED); disconnect(null); } if (mClientConnected == true) { onConnectionStateChanged(mDevice, BluetoothProfile.STATE_CONNECTING, BluetoothProfile.STATE_CONNECTED); processNextRequest(); } } public void handleConnect(BluetoothDevice device) { private class ConnectionHandler extends Handler { public static final int EVENT_CONNECT = 1; public static final int EVENT_DISCONNECT = 2; public ConnectionHandler(Looper looper) { super(looper); } @Override public void handleMessage(Message msg) { if (DBG) { Log.d(TAG, "Connection Handler Message " + msg.what + " with " + msg.obj); } switch (msg.what) { case EVENT_CONNECT: if (msg.obj instanceof BluetoothDevice) { BluetoothDevice device = (BluetoothDevice) msg.obj; int oldState = getConnectionState(); if (oldState != BluetoothProfile.STATE_DISCONNECTED) { return; } onConnectionStateChanged(device, oldState, BluetoothProfile.STATE_CONNECTING); handleConnect(device); } else { Log.e(TAG, "Invalid instance in Connection Handler:Connect"); } break; case EVENT_DISCONNECT: if (mDevice == null) { return; } if (msg.obj == null || msg.obj instanceof BluetoothDevice) { BluetoothDevice device = (BluetoothDevice) msg.obj; if (!mDevice.equals(device)) { return; } int oldState = getConnectionState(); handleDisconnect(device); int newState = getConnectionState(); if (device != null) { onConnectionStateChanged(device, oldState, newState); } } else { Log.e(TAG, "Invalid instance in Connection Handler:Disconnect"); } break; default: Log.e(TAG, "Unknown Request to Connection Handler"); break; } } private void handleConnect(BluetoothDevice device) { if (device == null) { throw new IllegalStateException(TAG + ":Connect with null device!"); } else if (mDevice != null && !mDevice.equals(device)) { Loading @@ -186,7 +245,7 @@ public class PbapPCEClient implements PbapHandler.PbapListener { mClient.connect(); } public void handleDisconnect(BluetoothDevice device) { private void handleDisconnect(BluetoothDevice device) { Log.w(TAG, "pbap disconnecting from = " + device); if (device == null) { Loading @@ -202,6 +261,25 @@ public class PbapPCEClient implements PbapHandler.PbapListener { } resetState(); } } private void onConnectionStateChanged(BluetoothDevice device, int prevState, int state) { Intent intent = new Intent(android.bluetooth.BluetoothPbapClient.ACTION_CONNECTION_STATE_CHANGED); intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState); intent.putExtra(BluetoothProfile.EXTRA_STATE, state); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); mContext.sendBroadcast(intent, ProfileService.BLUETOOTH_PERM); Log.d(TAG,"Connection state " + device + ": " + prevState + "->" + state); } public void connect(BluetoothDevice device) { mConnectionHandler.obtainMessage(ConnectionHandler.EVENT_CONNECT,device).sendToTarget(); } public void disconnect(BluetoothDevice device) { mConnectionHandler.obtainMessage(ConnectionHandler.EVENT_DISCONNECT,device).sendToTarget(); } public void start() { if (mDevice != null) { Loading Loading @@ -293,6 +371,8 @@ public class PbapPCEClient implements PbapHandler.PbapListener { if (msg.obj instanceof Account) { Account account = (Account) msg.obj; addAccount(account); } else { Log.e(TAG, "invalid Instance in Contact Handler: Add Account"); } break; Loading @@ -300,9 +380,8 @@ public class PbapPCEClient implements PbapHandler.PbapListener { if (msg.obj instanceof PullRequest) { PullRequest req = (PullRequest) msg.obj; req.onPullComplete(); } else { Log.w(TAG, "invalid Instance in contact handler"); } else { Log.e(TAG, "invalid Instance in Contact Handler: Add Contacts"); } break; Loading