Skip to content

Commit bd01887

Browse files
committed
BT connection are closed correctly when BT is switched off even from outside app. Still: Other side becomes not aware of connection breakdown.
1 parent 6c0c049 commit bd01887

4 files changed

Lines changed: 26 additions & 15 deletions

File tree

app/libs/ASAP_Engine_0.5.0.jar

419 Bytes
Binary file not shown.

app/src/main/java/net/sharksystem/asap/android/bluetooth/BluetoothEngine.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private void setup() {
165165
}
166166

167167

168-
void acceptServerSocketKilled() {
168+
void doServerAcceptSocketKilled() {
169169
Log.d(this.getLogStart(), "was told accept socket died - shutdown");
170170
// server socket was killed - that most probably because BT was switched off by users
171171
try {
@@ -179,7 +179,7 @@ void acceptServerSocketKilled() {
179179
*/
180180

181181
for(BluetoothSocket socket : this.openSockets.values()) {
182-
String name = "no remote Device";
182+
String name = "no remote device";
183183
String address = name;
184184
BluetoothDevice remoteDevice = socket.getRemoteDevice();
185185
if( remoteDevice != null) {
@@ -192,7 +192,8 @@ void acceptServerSocketKilled() {
192192
+ " | address: " + address
193193
+ " | isConnected: " + socket.isConnected());
194194
try {
195-
socket.getInputStream().close();
195+
this.kill(address); // kill connection that runs on top of it
196+
socket.getInputStream().close(); // and underlying sockets
196197
socket.getOutputStream().close();
197198
} catch (IOException e) {
198199
Log.d(this.getLogStart(), "could not close");

app/src/main/java/net/sharksystem/asap/android/bluetooth/BluetoothServerSocketThread.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public void run() {
5050
// possible parallel connection are handle by BT engine
5151
this.btEngine.handleBTSocket(socket);
5252
} catch (IOException e) {
53-
Log.d(this.getLogStart(), "Socket's accept() method failed", e);
53+
Log.d(this.getLogStart(), "Socket's accept() method failed: " + e.getLocalizedMessage());
5454
// tell engine
55-
this.btEngine.acceptServerSocketKilled();
55+
this.btEngine.doServerAcceptSocketKilled();
5656
break;
5757
}
5858
}

app/src/main/java/net/sharksystem/asap/android/service/MacLayerEngine.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,34 @@ private String getLogStart() {
104104
return "ASAPMacLayerEngine";
105105
}
106106

107+
private Map<String, ASAPConnection> asapConnections = new HashMap<>();
108+
109+
/**
110+
* kill connection to address
111+
* @param address
112+
*/
113+
protected void kill(String address) {
114+
ASAPConnection asapConnection = this.asapConnections.get(address);
115+
if(asapConnection != null) {
116+
Log.d(this.getLogStart(), "going kill connection to: " + address);
117+
asapConnection.kill();
118+
} else {
119+
Log.d(this.getLogStart(), "no connection to kill to: " + address);
120+
}
121+
}
122+
107123
protected void launchASAPConnection(
108124
String address, InputStream inputStream, OutputStream outputStream) {
109-
/*
110-
// set up new ASAP Session on that connection
111-
ASAPConnectionLauncher asapConnectionLauncher =
112-
new ASAPConnectionLauncher(
113-
inputStream, outputStream, this.getAsapService().getASAPEngine());
114-
115-
asapConnectionLauncher.start();
116-
*/
125+
117126
Log.d(this.getLogStart(), "going to launch a new asap connection");
118127

119128
try {
120129
Log.d(this.getLogStart(), "call asapMultiEngine to handle connection");
121130
// TestConnectionHandler testConnectionHandler = new TestConnectionHandler(this.is, this.os);
122131
// testConnectionHandler.start();
123-
ASAPConnection asapConnection =
124-
this.getAsapService().getASAPEngine().handleConnection(inputStream, outputStream);
132+
this.asapConnections.put(address,
133+
this.getAsapService().getASAPEngine().handleConnection(inputStream, outputStream));
134+
125135
} catch (IOException | ASAPException e) {
126136
Log.d(this.getLogStart(), "while lauching asap connection: " + e.getLocalizedMessage());
127137
}

0 commit comments

Comments
 (0)