@Test public void testConnect_noDevice() throws Exception { assertThat("Is false as no bluetooth device is provided", mBluetoothConnector.connect(null, mMockPeerProperties), is(false)); }
public synchronized boolean connect( BluetoothDevice bluetoothDeviceToConnectTo, PeerProperties peerProperties) { boolean wasSuccessful = false; String errorMessage = ""; if (bluetoothDeviceToConnectTo != null) { final String bluetoothDeviceName = bluetoothDeviceToConnectTo.getName(); final String bluetoothDeviceAddress = bluetoothDeviceToConnectTo.getAddress(); Log.i(TAG, "connect: Trying to start connecting to " + bluetoothDeviceName + " in address " + bluetoothDeviceAddress); BluetoothClientThread bluetoothClientThread = null; try { bluetoothClientThread = new BluetoothClientThread( this, bluetoothDeviceToConnectTo, mServiceRecordUuid, mMyIdentityString); } catch (IOException e) { errorMessage = "connect: Failed to create a Bluetooth connect thread instance: " + e.getMessage(); Log.e(TAG, errorMessage, e); } if (bluetoothClientThread != null) { bluetoothClientThread.setUncaughtExceptionHandler(mUncaughtExceptionHandler); bluetoothClientThread.setHandshakeRequired(mHandshakeRequired); bluetoothClientThread.setPeerProperties(peerProperties); bluetoothClientThread.setInsecureRfcommSocketPortNumber(mInsecureRfcommSocketPort); bluetoothClientThread.setMaxNumberOfRetries(mMaxNumberOfOutgoingConnectionAttemptRetries); mClientThreads.add(bluetoothClientThread); if (mConnectionTimeoutTimer == null) { try { createConnectionTimeoutTimer(); mConnectionTimeoutTimer.start(); } catch (RuntimeException e) { Log.e(TAG, "connect: Failed to create the connection timeout timer: " + e.getMessage(), e); } } bluetoothClientThread.start(); mListener.onConnecting(bluetoothDeviceName, bluetoothDeviceAddress); wasSuccessful = true; Log.d(TAG, "connect: Started connecting to " + bluetoothDeviceName + " in address " + bluetoothDeviceAddress); } else { mListener.onConnectionFailed(peerProperties, errorMessage); } } else { Log.e(TAG, "connect: No bluetooth device!"); } return wasSuccessful; }
BluetoothConnector implements BluetoothServerThread.Listener, BluetoothClientThread.Listener { public synchronized boolean connect( BluetoothDevice bluetoothDeviceToConnectTo, PeerProperties peerProperties) { boolean wasSuccessful = false; String errorMessage = ""; if (bluetoothDeviceToConnectTo != null) { final String bluetoothDeviceName = bluetoothDeviceToConnectTo.getName(); final String bluetoothDeviceAddress = bluetoothDeviceToConnectTo.getAddress(); Log.i(TAG, "connect: Trying to start connecting to " + bluetoothDeviceName + " in address " + bluetoothDeviceAddress); BluetoothClientThread bluetoothClientThread = null; try { bluetoothClientThread = new BluetoothClientThread( this, bluetoothDeviceToConnectTo, mServiceRecordUuid, mMyIdentityString); } catch (IOException e) { errorMessage = "connect: Failed to create a Bluetooth connect thread instance: " + e.getMessage(); Log.e(TAG, errorMessage, e); } if (bluetoothClientThread != null) { bluetoothClientThread.setUncaughtExceptionHandler(mUncaughtExceptionHandler); bluetoothClientThread.setHandshakeRequired(mHandshakeRequired); bluetoothClientThread.setPeerProperties(peerProperties); bluetoothClientThread.setInsecureRfcommSocketPortNumber(mInsecureRfcommSocketPort); bluetoothClientThread.setMaxNumberOfRetries(mMaxNumberOfOutgoingConnectionAttemptRetries); mClientThreads.add(bluetoothClientThread); if (mConnectionTimeoutTimer == null) { try { createConnectionTimeoutTimer(); mConnectionTimeoutTimer.start(); } catch (RuntimeException e) { Log.e(TAG, "connect: Failed to create the connection timeout timer: " + e.getMessage(), e); } } bluetoothClientThread.start(); mListener.onConnecting(bluetoothDeviceName, bluetoothDeviceAddress); wasSuccessful = true; Log.d(TAG, "connect: Started connecting to " + bluetoothDeviceName + " in address " + bluetoothDeviceAddress); } else { mListener.onConnectionFailed(peerProperties, errorMessage); } } else { Log.e(TAG, "connect: No bluetooth device!"); } return wasSuccessful; } }
BluetoothConnector implements BluetoothServerThread.Listener, BluetoothClientThread.Listener { public synchronized boolean connect( BluetoothDevice bluetoothDeviceToConnectTo, PeerProperties peerProperties) { boolean wasSuccessful = false; String errorMessage = ""; if (bluetoothDeviceToConnectTo != null) { final String bluetoothDeviceName = bluetoothDeviceToConnectTo.getName(); final String bluetoothDeviceAddress = bluetoothDeviceToConnectTo.getAddress(); Log.i(TAG, "connect: Trying to start connecting to " + bluetoothDeviceName + " in address " + bluetoothDeviceAddress); BluetoothClientThread bluetoothClientThread = null; try { bluetoothClientThread = new BluetoothClientThread( this, bluetoothDeviceToConnectTo, mServiceRecordUuid, mMyIdentityString); } catch (IOException e) { errorMessage = "connect: Failed to create a Bluetooth connect thread instance: " + e.getMessage(); Log.e(TAG, errorMessage, e); } if (bluetoothClientThread != null) { bluetoothClientThread.setUncaughtExceptionHandler(mUncaughtExceptionHandler); bluetoothClientThread.setHandshakeRequired(mHandshakeRequired); bluetoothClientThread.setPeerProperties(peerProperties); bluetoothClientThread.setInsecureRfcommSocketPortNumber(mInsecureRfcommSocketPort); bluetoothClientThread.setMaxNumberOfRetries(mMaxNumberOfOutgoingConnectionAttemptRetries); mClientThreads.add(bluetoothClientThread); if (mConnectionTimeoutTimer == null) { try { createConnectionTimeoutTimer(); mConnectionTimeoutTimer.start(); } catch (RuntimeException e) { Log.e(TAG, "connect: Failed to create the connection timeout timer: " + e.getMessage(), e); } } bluetoothClientThread.start(); mListener.onConnecting(bluetoothDeviceName, bluetoothDeviceAddress); wasSuccessful = true; Log.d(TAG, "connect: Started connecting to " + bluetoothDeviceName + " in address " + bluetoothDeviceAddress); } else { mListener.onConnectionFailed(peerProperties, errorMessage); } } else { Log.e(TAG, "connect: No bluetooth device!"); } return wasSuccessful; } BluetoothConnector(
            Context context, BluetoothConnectorListener listener, BluetoothAdapter bluetoothAdapter,
            UUID serviceRecordUuid, String myBluetoothName, String myIdentityString);  BluetoothConnector(
            Context context, BluetoothConnectorListener listener, BluetoothAdapter bluetoothAdapter,
            UUID serviceRecordUuid, String myBluetoothName, String myIdentityString,
            SharedPreferences preferences); }
BluetoothConnector implements BluetoothServerThread.Listener, BluetoothClientThread.Listener { public synchronized boolean connect( BluetoothDevice bluetoothDeviceToConnectTo, PeerProperties peerProperties) { boolean wasSuccessful = false; String errorMessage = ""; if (bluetoothDeviceToConnectTo != null) { final String bluetoothDeviceName = bluetoothDeviceToConnectTo.getName(); final String bluetoothDeviceAddress = bluetoothDeviceToConnectTo.getAddress(); Log.i(TAG, "connect: Trying to start connecting to " + bluetoothDeviceName + " in address " + bluetoothDeviceAddress); BluetoothClientThread bluetoothClientThread = null; try { bluetoothClientThread = new BluetoothClientThread( this, bluetoothDeviceToConnectTo, mServiceRecordUuid, mMyIdentityString); } catch (IOException e) { errorMessage = "connect: Failed to create a Bluetooth connect thread instance: " + e.getMessage(); Log.e(TAG, errorMessage, e); } if (bluetoothClientThread != null) { bluetoothClientThread.setUncaughtExceptionHandler(mUncaughtExceptionHandler); bluetoothClientThread.setHandshakeRequired(mHandshakeRequired); bluetoothClientThread.setPeerProperties(peerProperties); bluetoothClientThread.setInsecureRfcommSocketPortNumber(mInsecureRfcommSocketPort); bluetoothClientThread.setMaxNumberOfRetries(mMaxNumberOfOutgoingConnectionAttemptRetries); mClientThreads.add(bluetoothClientThread); if (mConnectionTimeoutTimer == null) { try { createConnectionTimeoutTimer(); mConnectionTimeoutTimer.start(); } catch (RuntimeException e) { Log.e(TAG, "connect: Failed to create the connection timeout timer: " + e.getMessage(), e); } } bluetoothClientThread.start(); mListener.onConnecting(bluetoothDeviceName, bluetoothDeviceAddress); wasSuccessful = true; Log.d(TAG, "connect: Started connecting to " + bluetoothDeviceName + " in address " + bluetoothDeviceAddress); } else { mListener.onConnectionFailed(peerProperties, errorMessage); } } else { Log.e(TAG, "connect: No bluetooth device!"); } return wasSuccessful; } BluetoothConnector(
            Context context, BluetoothConnectorListener listener, BluetoothAdapter bluetoothAdapter,
            UUID serviceRecordUuid, String myBluetoothName, String myIdentityString);  BluetoothConnector(
            Context context, BluetoothConnectorListener listener, BluetoothAdapter bluetoothAdapter,
            UUID serviceRecordUuid, String myBluetoothName, String myIdentityString,
            SharedPreferences preferences); void setIdentityString(String myIdentityString); void setConnectionTimeout(long connectionTimeoutInMilliseconds); void setInsecureRfcommSocketPort(int insecureRfcommSocketPort); void setMaxNumberOfOutgoingConnectionAttemptRetries(int maxNumberOfRetries); void setHandshakeRequired(boolean handshakeRequired); synchronized boolean startListeningForIncomingConnections(); synchronized void stopListeningForIncomingConnections(); synchronized void shutdown(); synchronized boolean connect(
            BluetoothDevice bluetoothDeviceToConnectTo, PeerProperties peerProperties); synchronized boolean cancelConnectionAttempt(PeerProperties peerProperties); synchronized void cancelAllConnectionAttempts(); @Override void onIncomingConnectionConnected(
            final BluetoothSocket bluetoothSocket, final PeerProperties peerProperties); @Override void onIncomingConnectionFailed(String errorMessage); @Override void onServerStopped(); @Override void onBluetoothServerSocketConsecutiveCreationFailureCountLimitExceeded(int limit); @Override void onSocketConnected(
            BluetoothSocket bluetoothSocket, PeerProperties peerProperties, BluetoothClientThread who); @Override void onHandshakeSucceeded(
            BluetoothSocket bluetoothSocket, PeerProperties peerProperties, BluetoothClientThread who); @Override void onConnectionFailed(PeerProperties peerProperties, String errorMessage, BluetoothClientThread who); }
BluetoothConnector implements BluetoothServerThread.Listener, BluetoothClientThread.Listener { public synchronized boolean connect( BluetoothDevice bluetoothDeviceToConnectTo, PeerProperties peerProperties) { boolean wasSuccessful = false; String errorMessage = ""; if (bluetoothDeviceToConnectTo != null) { final String bluetoothDeviceName = bluetoothDeviceToConnectTo.getName(); final String bluetoothDeviceAddress = bluetoothDeviceToConnectTo.getAddress(); Log.i(TAG, "connect: Trying to start connecting to " + bluetoothDeviceName + " in address " + bluetoothDeviceAddress); BluetoothClientThread bluetoothClientThread = null; try { bluetoothClientThread = new BluetoothClientThread( this, bluetoothDeviceToConnectTo, mServiceRecordUuid, mMyIdentityString); } catch (IOException e) { errorMessage = "connect: Failed to create a Bluetooth connect thread instance: " + e.getMessage(); Log.e(TAG, errorMessage, e); } if (bluetoothClientThread != null) { bluetoothClientThread.setUncaughtExceptionHandler(mUncaughtExceptionHandler); bluetoothClientThread.setHandshakeRequired(mHandshakeRequired); bluetoothClientThread.setPeerProperties(peerProperties); bluetoothClientThread.setInsecureRfcommSocketPortNumber(mInsecureRfcommSocketPort); bluetoothClientThread.setMaxNumberOfRetries(mMaxNumberOfOutgoingConnectionAttemptRetries); mClientThreads.add(bluetoothClientThread); if (mConnectionTimeoutTimer == null) { try { createConnectionTimeoutTimer(); mConnectionTimeoutTimer.start(); } catch (RuntimeException e) { Log.e(TAG, "connect: Failed to create the connection timeout timer: " + e.getMessage(), e); } } bluetoothClientThread.start(); mListener.onConnecting(bluetoothDeviceName, bluetoothDeviceAddress); wasSuccessful = true; Log.d(TAG, "connect: Started connecting to " + bluetoothDeviceName + " in address " + bluetoothDeviceAddress); } else { mListener.onConnectionFailed(peerProperties, errorMessage); } } else { Log.e(TAG, "connect: No bluetooth device!"); } return wasSuccessful; } BluetoothConnector(
            Context context, BluetoothConnectorListener listener, BluetoothAdapter bluetoothAdapter,
            UUID serviceRecordUuid, String myBluetoothName, String myIdentityString);  BluetoothConnector(
            Context context, BluetoothConnectorListener listener, BluetoothAdapter bluetoothAdapter,
            UUID serviceRecordUuid, String myBluetoothName, String myIdentityString,
            SharedPreferences preferences); void setIdentityString(String myIdentityString); void setConnectionTimeout(long connectionTimeoutInMilliseconds); void setInsecureRfcommSocketPort(int insecureRfcommSocketPort); void setMaxNumberOfOutgoingConnectionAttemptRetries(int maxNumberOfRetries); void setHandshakeRequired(boolean handshakeRequired); synchronized boolean startListeningForIncomingConnections(); synchronized void stopListeningForIncomingConnections(); synchronized void shutdown(); synchronized boolean connect(
            BluetoothDevice bluetoothDeviceToConnectTo, PeerProperties peerProperties); synchronized boolean cancelConnectionAttempt(PeerProperties peerProperties); synchronized void cancelAllConnectionAttempts(); @Override void onIncomingConnectionConnected(
            final BluetoothSocket bluetoothSocket, final PeerProperties peerProperties); @Override void onIncomingConnectionFailed(String errorMessage); @Override void onServerStopped(); @Override void onBluetoothServerSocketConsecutiveCreationFailureCountLimitExceeded(int limit); @Override void onSocketConnected(
            BluetoothSocket bluetoothSocket, PeerProperties peerProperties, BluetoothClientThread who); @Override void onHandshakeSucceeded(
            BluetoothSocket bluetoothSocket, PeerProperties peerProperties, BluetoothClientThread who); @Override void onConnectionFailed(PeerProperties peerProperties, String errorMessage, BluetoothClientThread who); static final long DEFAULT_CONNECTION_TIMEOUT_IN_MILLISECONDS; static final int SYSTEM_DECIDED_INSECURE_RFCOMM_SOCKET_PORT; static final int DEFAULT_ALTERNATIVE_INSECURE_RFCOMM_SOCKET_PORT; static final int DEFAULT_MAX_NUMBER_OF_RETRIES; static final boolean DEFAULT_HANDSHAKE_REQUIRED; }