BluetoothUtils { public static void setNextAlternativeChannelOrPort(int channelOrPort) { if (channelOrPort >= 1 && channelOrPort < MAX_ALTERNATIVE_CHANNEL) { mAlternativeChannel = channelOrPort - 1; } }  static boolean isBluetoothMacAddressUnknown(String bluetoothMacAddress); static boolean isValidBluetoothMacAddress(String bluetoothMacAddress); static String getBluetoothMacAddressFromSocket(final BluetoothSocket bluetoothSocket); static PeerProperties validateReceivedHandshakeMessage(
            byte[] handshakeMessage, int handshakeMessageLength, BluetoothSocket bluetoothSocketOfSender); static int getPreviouslyUsedAlternativeChannelOrPort(); static void setNextAlternativeChannelOrPort(int channelOrPort); static BluetoothSocket createBluetoothSocketToServiceRecord(
            BluetoothDevice bluetoothDevice, UUID serviceRecordUuid, int channelOrPort, boolean secure); static BluetoothSocket createBluetoothSocketToServiceRecordWithNextPort(
            BluetoothDevice bluetoothDevice, UUID serviceRecordUuid, boolean secure); static BluetoothSocket createBluetoothSocket(
            BluetoothSocket originalBluetoothSocket, int channelOrPort, boolean secure); static BluetoothSocket createBluetoothSocketWithNextChannel(
            BluetoothSocket originalBluetoothSocket, boolean secure); static final String BLUETOOTH_ADDRESS_SEPARATOR; static final int BLUETOOTH_ADDRESS_BYTE_COUNT; static final int BLUETOOTH_MAC_ADDRESS_STRING_LENGTH_MIN; static final int BLUETOOTH_MAC_ADDRESS_STRING_LENGTH_MAX; static final String SIMPLE_HANDSHAKE_MESSAGE_AS_STRING; static final byte[] SIMPLE_HANDSHAKE_MESSAGE_AS_BYTE_ARRAY; }
@Test public void testSetNextAlternativeChannelOrPort() throws Exception { int MAX_ALTERNATIVE_CHANNEL = 30; int tmpChPort = BluetoothUtils.getPreviouslyUsedAlternativeChannelOrPort(); BluetoothUtils.setNextAlternativeChannelOrPort(-1); assertThat("It returns previous port if the alternative RFCOMM channel is below 0 or not set", BluetoothUtils.getPreviouslyUsedAlternativeChannelOrPort(), is(tmpChPort)); tmpChPort = BluetoothUtils.getPreviouslyUsedAlternativeChannelOrPort(); BluetoothUtils.setNextAlternativeChannelOrPort(0); assertThat("It returns previous port if the alternative RFCOMM channel is 0", BluetoothUtils.getPreviouslyUsedAlternativeChannelOrPort(), is(tmpChPort)); BluetoothUtils.setNextAlternativeChannelOrPort(MAX_ALTERNATIVE_CHANNEL - 1); assertThat("It returns proper alternative RFCOMM channel", BluetoothUtils.getPreviouslyUsedAlternativeChannelOrPort(), is(MAX_ALTERNATIVE_CHANNEL - 2)); BluetoothUtils.setNextAlternativeChannelOrPort(MAX_ALTERNATIVE_CHANNEL); assertThat("It returns proper alternative RFCOMM channel", BluetoothUtils.getPreviouslyUsedAlternativeChannelOrPort(), is(MAX_ALTERNATIVE_CHANNEL - 2)); }