Loading AndroidManifest.xml +1 −0 Original line number Original line Diff line number Diff line Loading @@ -51,6 +51,7 @@ <uses-permission android:name="android.permission.BLUETOOTH_STACK" /> <uses-permission android:name="android.permission.BLUETOOTH_STACK" /> <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/> <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/> <uses-permission android:name="android.permission.MANAGE_USERS"/> <uses-permission android:name="android.permission.MANAGE_USERS"/> <uses-permission android:name="android.permission.GET_ACCOUNTS"/> <uses-permission android:name="com.google.android.gallery3d.permission.GALLERY_PROVIDER"/> <uses-permission android:name="com.google.android.gallery3d.permission.GALLERY_PROVIDER"/> <uses-permission android:name="com.android.gallery3d.permission.GALLERY_PROVIDER"/> <uses-permission android:name="com.android.gallery3d.permission.GALLERY_PROVIDER"/> <uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.RECEIVE_SMS" /> Loading src/com/android/bluetooth/btservice/AdapterService.java +105 −17 Original line number Original line Diff line number Diff line Loading @@ -1680,11 +1680,13 @@ public class AdapterService extends Service { } } for (BluetoothDevice device : bondedDevices) { for (BluetoothDevice device : bondedDevices) { if (headsetClientService.getPriority(device) == BluetoothProfile.PRIORITY_AUTO_CONNECT){ debugLog("autoConnectHeadsetClient() - Connecting Headset Client with " + debugLog("autoConnectHeadsetClient() - Connecting Headset Client with " + device.toString()); device.toString()); headsetClientService.connect(device); headsetClientService.connect(device); } } } } } private void autoConnectA2dpSink() { private void autoConnectA2dpSink() { A2dpSinkService a2dpSinkService = A2dpSinkService.getA2dpSinkService(); A2dpSinkService a2dpSinkService = A2dpSinkService.getA2dpSinkService(); Loading @@ -1694,10 +1696,12 @@ public class AdapterService extends Service { } } for (BluetoothDevice device : bondedDevices) { for (BluetoothDevice device : bondedDevices) { if (a2dpSinkService.getPriority(device) == BluetoothProfile.PRIORITY_AUTO_CONNECT) { debugLog("autoConnectA2dpSink() - Connecting A2DP Sink with " + device.toString()); debugLog("autoConnectA2dpSink() - Connecting A2DP Sink with " + device.toString()); a2dpSinkService.connect(device); a2dpSinkService.connect(device); } } } } } private void autoConnectPbapClient(){ private void autoConnectPbapClient(){ PbapClientService pbapClientService = PbapClientService.getPbapClientService(); PbapClientService pbapClientService = PbapClientService.getPbapClientService(); Loading @@ -1706,8 +1710,9 @@ public class AdapterService extends Service { return; return; } } for (BluetoothDevice device : bondedDevices) { for (BluetoothDevice device : bondedDevices) { if (pbapClientService.getPriority(device) >= BluetoothProfile.PRIORITY_ON ){ if (pbapClientService.getPriority(device) == BluetoothProfile.PRIORITY_AUTO_CONNECT) { debugLog("autoConnectPbapClient() - Connecting PBAP Client with " + device.toString()); debugLog("autoConnectPbapClient() - Connecting PBAP Client with " + device.toString()); pbapClientService.connect(device); pbapClientService.connect(device); } } } } Loading Loading @@ -1766,8 +1771,49 @@ 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); } } } private void adjustOtherHeadsetClientPriorities(HeadsetClientService hsService, BluetoothDevice connectedDevice) { for (BluetoothDevice device : getBondedDevices()) { if (hsService.getPriority(device) >= BluetoothProfile.PRIORITY_AUTO_CONNECT && !device.equals(connectedDevice)) { hsService.setPriority(device, BluetoothProfile.PRIORITY_ON); } } } private void adjustOtherA2dpSinkPriorities(A2dpSinkService a2dpService, BluetoothDevice connectedDevice) { for (BluetoothDevice device : getBondedDevices()) { if (a2dpService.getPriority(device) >= BluetoothProfile.PRIORITY_AUTO_CONNECT && !device.equals(connectedDevice)) { a2dpService.setPriority(device, BluetoothProfile.PRIORITY_ON); } } } private void adjustOtherPbapClientPriorities(PbapClientService pbapService, BluetoothDevice connectedDevice) { for (BluetoothDevice device : getBondedDevices()) { if (pbapService.getPriority(device) >= BluetoothProfile.PRIORITY_AUTO_CONNECT && !device.equals(connectedDevice)) { pbapService.setPriority(device, BluetoothProfile.PRIORITY_ON); } } } void setProfileAutoConnectionPriority (BluetoothDevice device, int profileId){ void setProfileAutoConnectionPriority (BluetoothDevice device, int profileId){ if (profileId == BluetoothProfile.HEADSET) { switch (profileId) { case BluetoothProfile.HEADSET: HeadsetService hsService = HeadsetService.getHeadsetService(); HeadsetService hsService = HeadsetService.getHeadsetService(); List<BluetoothDevice> deviceList = hsService.getConnectedDevices(); List<BluetoothDevice> deviceList = hsService.getConnectedDevices(); if ((hsService != null) && if ((hsService != null) && Loading @@ -1775,6 +1821,48 @@ public class AdapterService extends Service { adjustOtherHeadsetPriorities(hsService, deviceList); adjustOtherHeadsetPriorities(hsService, deviceList); hsService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT); hsService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT); } } break; case BluetoothProfile.A2DP: A2dpService a2dpService = A2dpService.getA2dpService(); if ((a2dpService != null) && (BluetoothProfile.PRIORITY_AUTO_CONNECT != a2dpService.getPriority(device))) { adjustOtherSinkPriorities(a2dpService, device); a2dpService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT); } break; case BluetoothProfile.A2DP_SINK: A2dpSinkService a2dpSinkService = A2dpSinkService.getA2dpSinkService(); if ((a2dpSinkService != null) && (BluetoothProfile.PRIORITY_AUTO_CONNECT != a2dpSinkService.getPriority(device))) { adjustOtherA2dpSinkPriorities(a2dpSinkService, device); a2dpSinkService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT); } break; case BluetoothProfile.HEADSET_CLIENT: HeadsetClientService headsetClientService = HeadsetClientService.getHeadsetClientService(); if ((headsetClientService != null) && (BluetoothProfile.PRIORITY_AUTO_CONNECT != headsetClientService.getPriority(device))) { adjustOtherHeadsetClientPriorities(headsetClientService, device); headsetClientService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT); } break; case BluetoothProfile.PBAP_CLIENT: PbapClientService pbapClientService = PbapClientService.getPbapClientService(); if ((pbapClientService != null) && (BluetoothProfile.PRIORITY_AUTO_CONNECT != pbapClientService.getPriority(device))) { adjustOtherPbapClientPriorities(pbapClientService, device); pbapClientService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT); } break; default: Log.w(TAG, "Attempting to set Auto Connect priority on invalid profile"); break; } } } } Loading src/com/android/bluetooth/pbapclient/PbapClientService.java +0 −16 Original line number Original line Diff line number Diff line Loading @@ -62,22 +62,6 @@ public class PbapClientService extends ProfileService { private static PbapClientService sPbapClientService; private static PbapClientService sPbapClientService; private PbapBroadcastReceiver mPbapBroadcastReceiver = new PbapBroadcastReceiver(); private PbapBroadcastReceiver mPbapBroadcastReceiver = new PbapBroadcastReceiver(); private Account getAccount(BluetoothDevice device) { Account account = null; Account[] accounts = mAccountManager. getAccountsByType("com.android.bluetooth.pbapclient"); for (Account acc : accounts) { if (acc.name.equals(device.getAddress())) { account = acc; } } if (account == null) { account = new Account(device.getAddress(), "com.android.bluetooth.pbapclient"); mAccountManager.addAccountExplicitly(account, null, null); } return account; } @Override @Override protected String getName() { protected String getName() { return TAG; return TAG; Loading src/com/android/bluetooth/pbapclient/PbapPCEClient.java +10 −7 Original line number Original line Diff line number Diff line Loading @@ -61,7 +61,7 @@ import java.lang.Thread; */ */ public class PbapPCEClient implements PbapHandler.PbapListener { public class PbapPCEClient implements PbapHandler.PbapListener { private static final String TAG = "PbapPCEClient"; private static final String TAG = "PbapPCEClient"; private static final boolean DBG = true; private static final boolean DBG = false; private final Queue<PullRequest> mPendingRequests = new ArrayDeque<PullRequest>(); private final Queue<PullRequest> mPendingRequests = new ArrayDeque<PullRequest>(); private BluetoothDevice mDevice; private BluetoothDevice mDevice; private BluetoothPbapClient mClient; private BluetoothPbapClient mClient; Loading Loading @@ -186,8 +186,6 @@ public class PbapPCEClient implements PbapHandler.PbapListener { if (oldState != BluetoothProfile.STATE_DISCONNECTED) { if (oldState != BluetoothProfile.STATE_DISCONNECTED) { return; return; } } onConnectionStateChanged(device, oldState, BluetoothProfile.STATE_CONNECTING); handleConnect(device); handleConnect(device); } else { } else { Log.e(TAG, "Invalid instance in Connection Handler:Connect"); Log.e(TAG, "Invalid instance in Connection Handler:Connect"); Loading Loading @@ -221,6 +219,7 @@ public class PbapPCEClient implements PbapHandler.PbapListener { } } private void handleConnect(BluetoothDevice device) { private void handleConnect(BluetoothDevice device) { Log.d(TAG,"HANDLECONNECT" + device); if (device == null) { if (device == null) { throw new IllegalStateException(TAG + ":Connect with null device!"); throw new IllegalStateException(TAG + ":Connect with null device!"); } else if (mDevice != null && !mDevice.equals(device)) { } else if (mDevice != null && !mDevice.equals(device)) { Loading @@ -236,10 +235,14 @@ public class PbapPCEClient implements PbapHandler.PbapListener { } } // Update the device. // Update the device. mDevice = device; mDevice = device; mClient = new BluetoothPbapClient(mDevice, mAccount, mHandler); onConnectionStateChanged(mDevice,BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.STATE_CONNECTING); // Add the account. This should give us a place to stash the data. // Add the account. This should give us a place to stash the data. mAccount = new Account(device.getAddress(), mContext.getString(R.string.pbap_account_type)); mAccount = new Account(device.getAddress(), mContactHandler.obtainMessage(ContactHandler.EVENT_ADD_ACCOUNT,mAccount).sendToTarget(); mContext.getString(R.string.pbap_account_type)); mContactHandler.obtainMessage(ContactHandler.EVENT_ADD_ACCOUNT, mAccount) .sendToTarget(); mClient = new BluetoothPbapClient(mDevice, mAccount, mHandler); downloadPhoneBook(); downloadPhoneBook(); downloadCallLogs(); downloadCallLogs(); mClient.connect(); mClient.connect(); Loading Loading @@ -420,7 +423,7 @@ public class PbapPCEClient implements PbapHandler.PbapListener { } } return true; return true; } } throw new IllegalStateException(TAG + ":Failed to add account!"); return false; } } private boolean removeAccount(Account acc) { private boolean removeAccount(Account acc) { Loading Loading
AndroidManifest.xml +1 −0 Original line number Original line Diff line number Diff line Loading @@ -51,6 +51,7 @@ <uses-permission android:name="android.permission.BLUETOOTH_STACK" /> <uses-permission android:name="android.permission.BLUETOOTH_STACK" /> <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/> <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/> <uses-permission android:name="android.permission.MANAGE_USERS"/> <uses-permission android:name="android.permission.MANAGE_USERS"/> <uses-permission android:name="android.permission.GET_ACCOUNTS"/> <uses-permission android:name="com.google.android.gallery3d.permission.GALLERY_PROVIDER"/> <uses-permission android:name="com.google.android.gallery3d.permission.GALLERY_PROVIDER"/> <uses-permission android:name="com.android.gallery3d.permission.GALLERY_PROVIDER"/> <uses-permission android:name="com.android.gallery3d.permission.GALLERY_PROVIDER"/> <uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.RECEIVE_SMS" /> Loading
src/com/android/bluetooth/btservice/AdapterService.java +105 −17 Original line number Original line Diff line number Diff line Loading @@ -1680,11 +1680,13 @@ public class AdapterService extends Service { } } for (BluetoothDevice device : bondedDevices) { for (BluetoothDevice device : bondedDevices) { if (headsetClientService.getPriority(device) == BluetoothProfile.PRIORITY_AUTO_CONNECT){ debugLog("autoConnectHeadsetClient() - Connecting Headset Client with " + debugLog("autoConnectHeadsetClient() - Connecting Headset Client with " + device.toString()); device.toString()); headsetClientService.connect(device); headsetClientService.connect(device); } } } } } private void autoConnectA2dpSink() { private void autoConnectA2dpSink() { A2dpSinkService a2dpSinkService = A2dpSinkService.getA2dpSinkService(); A2dpSinkService a2dpSinkService = A2dpSinkService.getA2dpSinkService(); Loading @@ -1694,10 +1696,12 @@ public class AdapterService extends Service { } } for (BluetoothDevice device : bondedDevices) { for (BluetoothDevice device : bondedDevices) { if (a2dpSinkService.getPriority(device) == BluetoothProfile.PRIORITY_AUTO_CONNECT) { debugLog("autoConnectA2dpSink() - Connecting A2DP Sink with " + device.toString()); debugLog("autoConnectA2dpSink() - Connecting A2DP Sink with " + device.toString()); a2dpSinkService.connect(device); a2dpSinkService.connect(device); } } } } } private void autoConnectPbapClient(){ private void autoConnectPbapClient(){ PbapClientService pbapClientService = PbapClientService.getPbapClientService(); PbapClientService pbapClientService = PbapClientService.getPbapClientService(); Loading @@ -1706,8 +1710,9 @@ public class AdapterService extends Service { return; return; } } for (BluetoothDevice device : bondedDevices) { for (BluetoothDevice device : bondedDevices) { if (pbapClientService.getPriority(device) >= BluetoothProfile.PRIORITY_ON ){ if (pbapClientService.getPriority(device) == BluetoothProfile.PRIORITY_AUTO_CONNECT) { debugLog("autoConnectPbapClient() - Connecting PBAP Client with " + device.toString()); debugLog("autoConnectPbapClient() - Connecting PBAP Client with " + device.toString()); pbapClientService.connect(device); pbapClientService.connect(device); } } } } Loading Loading @@ -1766,8 +1771,49 @@ 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); } } } private void adjustOtherHeadsetClientPriorities(HeadsetClientService hsService, BluetoothDevice connectedDevice) { for (BluetoothDevice device : getBondedDevices()) { if (hsService.getPriority(device) >= BluetoothProfile.PRIORITY_AUTO_CONNECT && !device.equals(connectedDevice)) { hsService.setPriority(device, BluetoothProfile.PRIORITY_ON); } } } private void adjustOtherA2dpSinkPriorities(A2dpSinkService a2dpService, BluetoothDevice connectedDevice) { for (BluetoothDevice device : getBondedDevices()) { if (a2dpService.getPriority(device) >= BluetoothProfile.PRIORITY_AUTO_CONNECT && !device.equals(connectedDevice)) { a2dpService.setPriority(device, BluetoothProfile.PRIORITY_ON); } } } private void adjustOtherPbapClientPriorities(PbapClientService pbapService, BluetoothDevice connectedDevice) { for (BluetoothDevice device : getBondedDevices()) { if (pbapService.getPriority(device) >= BluetoothProfile.PRIORITY_AUTO_CONNECT && !device.equals(connectedDevice)) { pbapService.setPriority(device, BluetoothProfile.PRIORITY_ON); } } } void setProfileAutoConnectionPriority (BluetoothDevice device, int profileId){ void setProfileAutoConnectionPriority (BluetoothDevice device, int profileId){ if (profileId == BluetoothProfile.HEADSET) { switch (profileId) { case BluetoothProfile.HEADSET: HeadsetService hsService = HeadsetService.getHeadsetService(); HeadsetService hsService = HeadsetService.getHeadsetService(); List<BluetoothDevice> deviceList = hsService.getConnectedDevices(); List<BluetoothDevice> deviceList = hsService.getConnectedDevices(); if ((hsService != null) && if ((hsService != null) && Loading @@ -1775,6 +1821,48 @@ public class AdapterService extends Service { adjustOtherHeadsetPriorities(hsService, deviceList); adjustOtherHeadsetPriorities(hsService, deviceList); hsService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT); hsService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT); } } break; case BluetoothProfile.A2DP: A2dpService a2dpService = A2dpService.getA2dpService(); if ((a2dpService != null) && (BluetoothProfile.PRIORITY_AUTO_CONNECT != a2dpService.getPriority(device))) { adjustOtherSinkPriorities(a2dpService, device); a2dpService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT); } break; case BluetoothProfile.A2DP_SINK: A2dpSinkService a2dpSinkService = A2dpSinkService.getA2dpSinkService(); if ((a2dpSinkService != null) && (BluetoothProfile.PRIORITY_AUTO_CONNECT != a2dpSinkService.getPriority(device))) { adjustOtherA2dpSinkPriorities(a2dpSinkService, device); a2dpSinkService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT); } break; case BluetoothProfile.HEADSET_CLIENT: HeadsetClientService headsetClientService = HeadsetClientService.getHeadsetClientService(); if ((headsetClientService != null) && (BluetoothProfile.PRIORITY_AUTO_CONNECT != headsetClientService.getPriority(device))) { adjustOtherHeadsetClientPriorities(headsetClientService, device); headsetClientService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT); } break; case BluetoothProfile.PBAP_CLIENT: PbapClientService pbapClientService = PbapClientService.getPbapClientService(); if ((pbapClientService != null) && (BluetoothProfile.PRIORITY_AUTO_CONNECT != pbapClientService.getPriority(device))) { adjustOtherPbapClientPriorities(pbapClientService, device); pbapClientService.setPriority(device,BluetoothProfile.PRIORITY_AUTO_CONNECT); } break; default: Log.w(TAG, "Attempting to set Auto Connect priority on invalid profile"); break; } } } } Loading
src/com/android/bluetooth/pbapclient/PbapClientService.java +0 −16 Original line number Original line Diff line number Diff line Loading @@ -62,22 +62,6 @@ public class PbapClientService extends ProfileService { private static PbapClientService sPbapClientService; private static PbapClientService sPbapClientService; private PbapBroadcastReceiver mPbapBroadcastReceiver = new PbapBroadcastReceiver(); private PbapBroadcastReceiver mPbapBroadcastReceiver = new PbapBroadcastReceiver(); private Account getAccount(BluetoothDevice device) { Account account = null; Account[] accounts = mAccountManager. getAccountsByType("com.android.bluetooth.pbapclient"); for (Account acc : accounts) { if (acc.name.equals(device.getAddress())) { account = acc; } } if (account == null) { account = new Account(device.getAddress(), "com.android.bluetooth.pbapclient"); mAccountManager.addAccountExplicitly(account, null, null); } return account; } @Override @Override protected String getName() { protected String getName() { return TAG; return TAG; Loading
src/com/android/bluetooth/pbapclient/PbapPCEClient.java +10 −7 Original line number Original line Diff line number Diff line Loading @@ -61,7 +61,7 @@ import java.lang.Thread; */ */ public class PbapPCEClient implements PbapHandler.PbapListener { public class PbapPCEClient implements PbapHandler.PbapListener { private static final String TAG = "PbapPCEClient"; private static final String TAG = "PbapPCEClient"; private static final boolean DBG = true; private static final boolean DBG = false; private final Queue<PullRequest> mPendingRequests = new ArrayDeque<PullRequest>(); private final Queue<PullRequest> mPendingRequests = new ArrayDeque<PullRequest>(); private BluetoothDevice mDevice; private BluetoothDevice mDevice; private BluetoothPbapClient mClient; private BluetoothPbapClient mClient; Loading Loading @@ -186,8 +186,6 @@ public class PbapPCEClient implements PbapHandler.PbapListener { if (oldState != BluetoothProfile.STATE_DISCONNECTED) { if (oldState != BluetoothProfile.STATE_DISCONNECTED) { return; return; } } onConnectionStateChanged(device, oldState, BluetoothProfile.STATE_CONNECTING); handleConnect(device); handleConnect(device); } else { } else { Log.e(TAG, "Invalid instance in Connection Handler:Connect"); Log.e(TAG, "Invalid instance in Connection Handler:Connect"); Loading Loading @@ -221,6 +219,7 @@ public class PbapPCEClient implements PbapHandler.PbapListener { } } private void handleConnect(BluetoothDevice device) { private void handleConnect(BluetoothDevice device) { Log.d(TAG,"HANDLECONNECT" + device); if (device == null) { if (device == null) { throw new IllegalStateException(TAG + ":Connect with null device!"); throw new IllegalStateException(TAG + ":Connect with null device!"); } else if (mDevice != null && !mDevice.equals(device)) { } else if (mDevice != null && !mDevice.equals(device)) { Loading @@ -236,10 +235,14 @@ public class PbapPCEClient implements PbapHandler.PbapListener { } } // Update the device. // Update the device. mDevice = device; mDevice = device; mClient = new BluetoothPbapClient(mDevice, mAccount, mHandler); onConnectionStateChanged(mDevice,BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.STATE_CONNECTING); // Add the account. This should give us a place to stash the data. // Add the account. This should give us a place to stash the data. mAccount = new Account(device.getAddress(), mContext.getString(R.string.pbap_account_type)); mAccount = new Account(device.getAddress(), mContactHandler.obtainMessage(ContactHandler.EVENT_ADD_ACCOUNT,mAccount).sendToTarget(); mContext.getString(R.string.pbap_account_type)); mContactHandler.obtainMessage(ContactHandler.EVENT_ADD_ACCOUNT, mAccount) .sendToTarget(); mClient = new BluetoothPbapClient(mDevice, mAccount, mHandler); downloadPhoneBook(); downloadPhoneBook(); downloadCallLogs(); downloadCallLogs(); mClient.connect(); mClient.connect(); Loading Loading @@ -420,7 +423,7 @@ public class PbapPCEClient implements PbapHandler.PbapListener { } } return true; return true; } } throw new IllegalStateException(TAG + ":Failed to add account!"); return false; } } private boolean removeAccount(Account acc) { private boolean removeAccount(Account acc) { Loading