mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-01 06:22:55 +01:00
Pebble LE/Pebble 2: Improve reconnect
This commit is contained in:
parent
092012ab31
commit
95ec1fb44c
@ -7,6 +7,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InterruptedIOException;
|
||||||
import java.io.PipedInputStream;
|
import java.io.PipedInputStream;
|
||||||
import java.io.PipedOutputStream;
|
import java.io.PipedOutputStream;
|
||||||
|
|
||||||
@ -69,13 +70,17 @@ public class PebbleLESupport {
|
|||||||
|
|
||||||
synchronized private void destroyPipedInputReader() {
|
synchronized private void destroyPipedInputReader() {
|
||||||
if (mPipeReader != null) {
|
if (mPipeReader != null) {
|
||||||
mPipeReader.quit();
|
|
||||||
mPipeReader.interrupt();
|
mPipeReader.interrupt();
|
||||||
try {
|
try {
|
||||||
mPipeReader.join();
|
mPipeReader.join();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOG.error(e.getMessage());
|
LOG.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
mPipedOutputStream.close();
|
||||||
|
} catch (IOException ignore) {
|
||||||
|
}
|
||||||
|
|
||||||
mPipeReader = null;
|
mPipeReader = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,13 +91,12 @@ public class PebbleLESupport {
|
|||||||
|
|
||||||
private class PipeReader extends Thread {
|
private class PipeReader extends Thread {
|
||||||
int mmSequence = 0;
|
int mmSequence = 0;
|
||||||
private boolean mQuit = false;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
byte[] buf = new byte[8192];
|
byte[] buf = new byte[8192];
|
||||||
int bytesRead;
|
int bytesRead;
|
||||||
while (!mQuit) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
// this code is very similar to iothread, that is bad
|
// this code is very similar to iothread, that is bad
|
||||||
// because we are the ones who prepared the buffer, there should be no
|
// because we are the ones who prepared the buffer, there should be no
|
||||||
@ -122,26 +126,22 @@ public class PebbleLESupport {
|
|||||||
payloadToSend -= chunkSize;
|
payloadToSend -= chunkSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(500); // FIXME ugly wait 0.5s after each pebble package send to the pebble (we do not wait for the GATT chunks)
|
Thread.sleep(500); // FIXME ugly wait 0.5s after each pebble package send to the pebble (we do not wait for the GATT chunks)
|
||||||
} catch (InterruptedException ignore) {
|
} catch (InterruptedIOException | InterruptedException e) {
|
||||||
}
|
Thread.currentThread().interrupt();
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOG.warn("IO exception");
|
|
||||||
mQuit = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
mPipedOutputStream.close();
|
|
||||||
mPipedInputStream.close();
|
|
||||||
} catch (IOException ignore) {
|
} catch (IOException ignore) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void quit() {
|
@Override
|
||||||
mQuit = true;
|
public void interrupt() {
|
||||||
|
super.interrupt();
|
||||||
|
try {
|
||||||
|
mPipedInputStream.close();
|
||||||
|
} catch (IOException ignore) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user