Minor clode cleanup.

This commit is contained in:
Felix Ableitner 2015-08-23 14:37:14 +02:00
parent 8b832cec9d
commit 578d8d9b76
4 changed files with 11 additions and 15 deletions

View file

@ -21,7 +21,7 @@ object BluetoothInterface {
/**
* Bluetooth service UUID version 5, created with namespace URL and "ensichat.nutomic.com".
*/
val AppUuid: UUID = UUID.fromString("8ed52b7a-4501-5348-b054-3d94d004656e")
val AppUuid = UUID.fromString("8ed52b7a-4501-5348-b054-3d94d004656e")
}

View file

@ -8,12 +8,11 @@ import android.util.Log
/**
* Attempts to connect to another device and calls [[onConnected]] on success.
*/
class ConnectThread(device: Device, onConnected: (Device, BluetoothSocket) => Unit)
extends Thread {
class ConnectThread(device: Device, onConnected: (Device, BluetoothSocket) => Unit) extends Thread {
private val Tag = "ConnectThread"
private val socket: BluetoothSocket =
private val socket =
device.bluetoothDevice.createInsecureRfcommSocketToServiceRecord(BluetoothInterface.AppUuid)
override def run(): Unit = {

View file

@ -13,9 +13,9 @@ import android.util.Log
class ListenThread(name: String, adapter: BluetoothAdapter,
onConnected: (Device, BluetoothSocket) => Unit) extends Thread {
private val Tag: String = "ListenThread"
private val Tag = "ListenThread"
private val serverSocket: BluetoothServerSocket =
private val serverSocket =
try {
adapter.listenUsingInsecureRfcommWithServiceRecord(name, BluetoothInterface.AppUuid)
} catch {

View file

@ -12,17 +12,14 @@ import Message.ReadMessageException
/**
* Transfers data between connnected devices.
*
* Messages must not be longer than [[TransferThread#MaxMessageLength]] bytes.
*
* @param device The bluetooth device to interact with.
* @param socket An open socket to the given device.
* @param onReceive Called when a message was received from the other device.
*/
class TransferThread(device: Device, socket: BluetoothSocket, Handler: BluetoothInterface,
Crypto: Crypto, onReceive: (Message, Device.ID) => Unit)
extends Thread {
class TransferThread(device: Device, socket: BluetoothSocket, handler: BluetoothInterface,
crypto: Crypto, onReceive: (Message, Device.ID) => Unit) extends Thread {
private val Tag: String = "TransferThread"
private val Tag = "TransferThread"
val inStream: InputStream =
try {
@ -45,8 +42,8 @@ class TransferThread(device: Device, socket: BluetoothSocket, Handler: Bluetooth
override def run(): Unit = {
Log.i(Tag, "Starting data transfer with " + device.toString)
send(Crypto.sign(new Message(new MessageHeader(ConnectionInfo.Type,
Address.Null, Address.Null, 0), new ConnectionInfo(Crypto.getLocalPublicKey))))
send(crypto.sign(new Message(new MessageHeader(ConnectionInfo.Type,
Address.Null, Address.Null, 0), new ConnectionInfo(crypto.getLocalPublicKey))))
while (socket.isConnected) {
try {
@ -81,7 +78,7 @@ class TransferThread(device: Device, socket: BluetoothSocket, Handler: Bluetooth
} catch {
case e: IOException => Log.e(Tag, "Failed to close socket", e);
} finally {
Handler.onConnectionClosed(new Device(device.bluetoothDevice, false), null)
handler.onConnectionClosed(new Device(device.bluetoothDevice, false), null)
}
}